<?php
require_once ('../lib/config.php');
require_once ('../lib/facebook.php');
require_once ('../lib/friends.php');
require_once ('../lib/friend.php');

$facebook = new Facebook(array(
    'appId' => FB_APP_ID,
    'secret' => FB_APP_SECRET,
    'cookie' => true
));


$me = null;

//Check if there is a session. Ensure that even if there is a session, we don't know it's valid or not until we make api call
if(isLoggedIn()){
    try{
        $me = $facebook->api('/me');
    }catch(FacebookApiException $e){
        error_log($e);
    }
}

//Buttongs
$logout_button = "<a href='".$facebook->getLogoutUrl()."'><img src='http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif'></a>"; 
$login_button = "<a href='".$facebook->getLoginUrl()."'><img src='http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif'></a>";

if(!$me){
    print $login_button;
    exit();
}else{
    print $logout_button;
}


if(!$me){
    exit();
}
/*
 * TEST CODE START
 */
try{
    $result = $facebook->api(array('method' => 'fql.query',
            'query' => "SELECT text, fromid FROM comment WHERE object_id = '100000416787478_170385092974030'"
        ));
        
    print_r($result);
}catch(FacebookApiException $e){
    print($e);
}
?>
